Added an xm console -q flag.
authorEwan Mellor <ewan@xensource.com>
Tue, 21 Nov 2006 11:21:20 +0000 (11:21 +0000)
committerEwan Mellor <ewan@xensource.com>
Tue, 21 Nov 2006 11:21:20 +0000 (11:21 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xm/main.py

index da664189d92b88a73ead4ff24a0208f010ecf3fd..46679b5d0e6fc55a583822d7b8d9c731ba2ede0f 100644 (file)
@@ -67,7 +67,7 @@ USAGE_FOOTER = '<Domain> can either be the Domain Name or Id.\n' \
 SUBCOMMAND_HELP = {
     # common commands
     
-    'console'     : ('<Domain>',
+    'console'     : ('[-q|--quiet] <Domain>',
                      'Attach to <Domain>\'s console.'),
     'create'      : ('<ConfigFile> [options] [vars]',
                      'Create a domain based on <ConfigFile>.'),
@@ -190,6 +190,9 @@ SUBCOMMAND_OPTIONS = {
        ('-l', '--long', 'Output all VM details in SXP'),
        ('', '--label',  'Include security labels'),
     ),
+    'console': (
+       ('-q', '--quiet', 'Do not print an error message if the domain does not exist'),
+    ),
     'dmesg': (
        ('-c', '--clear', 'Clear dmesg buffer'),
     ),
@@ -1002,15 +1005,46 @@ def xm_info(args):
             print "%-23s:" % x[0], x[1]
 
 def xm_console(args):
-    arg_check(args, "console", 1)
+    arg_check(args, "console", 1, 2)
 
-    dom = args[0]
-    info = server.xend.domain(dom)
+    quiet = False;
+
+    try:
+        (options, params) = getopt.gnu_getopt(args, 'q', ['quiet'])
+    except getopt.GetoptError, opterr:
+        err(opterr)
+        sys.exit(1)
+
+    for (k, v) in options:
+        if k in ['-q', '--quiet']:
+            quiet = True
+        else:
+            assert False
+
+    if len(params) != 1:
+        err('No domain given')
+        usage('console')
+        sys.exit(1)
+
+    dom = params[0]
+
+    try:
+        info = server.xend.domain(dom)
+    except:
+        if quiet:
+            sys.exit(1)
+        else:
+            raise
     domid = int(sxp.child_value(info, 'domid', '-1'))
     if domid == -1:
-        raise Exception("Domain is not started")
+        if quiet:
+            sys.exit(1)
+        else:
+            raise Exception("Domain is not started")
+
     console.execConsole(domid)
 
+
 def xm_uptime(args):
     short_mode = 0